#include "ModelControl.h"
#include "ui_ModelControl.h"
#include <QDebug>

ModelControl::ModelControl(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ModelControl)
{
    ui->setupUi(this);
    initSignals();
}

ModelControl::~ModelControl()
{
    delete ui;
}

void ModelControl::on_pb_machine_clicked()
{
    Weldroid::RobotPos pos = Weldroid::RobotPos::instance(ui->le_machine->text().toStdString());
    emit changePosition(sys::ENUM_MACHINE,pos);
}

void ModelControl::on_pb_robot_clicked()
{
    Weldroid::RobotPos d = Weldroid::RobotPos::instance(ui->le_robot->text().toStdString());
    emit changePosition(sys::ENUM_ROBOT,d);
}

void ModelControl::initSignals()
{
    connect(ui->hs_x,&QAbstractSlider::sliderMoved ,this,[=](int f){
        Pos3dzx p = Pos3dzx::instance();
        p.x = f;
        emit relativePositon(sys::ENUM_ROBOT,p);
        ui->hs_x->setValue(0);
    });
    connect(ui->hs_y,&QAbstractSlider::sliderMoved ,this,[=](int f){
        Pos3dzx p = Pos3dzx::instance();
        p.y = f;
        emit relativePositon(sys::ENUM_ROBOT,p);
        ui->hs_y->setValue(0);
    });
    connect(ui->hs_z,&QAbstractSlider::sliderMoved ,this,[=](int f){
        Pos3dzx p = Pos3dzx::instance();
        p.z = f;
        emit relativePositon(sys::ENUM_ROBOT,p);
        ui->hs_z->setValue(0);
    });
    connect(ui->hs_a,&QAbstractSlider::sliderMoved ,this,[=](int f){
        Pos3dzx p = Pos3dzx::instance();
        p.a = f;
        emit relativePositon(sys::ENUM_ROBOT,p);
        ui->hs_a->setValue(0);
    });
    connect(ui->hs_b,&QAbstractSlider::sliderMoved ,this,[=](int f){
        Pos3dzx p = Pos3dzx::instance();
        p.b = f;
        emit relativePositon(sys::ENUM_ROBOT,p);
        ui->hs_b->setValue(0);
    });
    connect(ui->hs_c,&QAbstractSlider::sliderMoved ,this,[=](int f){
        Pos3dzx p = Pos3dzx::instance();
        p.c = f;
        emit relativePositon(sys::ENUM_ROBOT,p);
        ui->hs_c->setValue(0);
    });
}
